package org.offsync.nio

import java.nio.channels.SelectionKey
import org.offsync.util.DisposableBase
import org.offsync.util.Disposer

class IoService extends DisposableBase {
  private val disposer = new Disposer()

  val acceptSelector = disposer.dependsOnAndDisposes{new Selector(SelectionKey.OP_ACCEPT)}
  val connectSelector = disposer.dependsOnAndDisposes{new Selector(SelectionKey.OP_CONNECT)}
  val readSelector = disposer.dependsOnAndDisposes{new Selector(SelectionKey.OP_READ)}
  val writeSelector = disposer.dependsOnAndDisposes{new Selector(SelectionKey.OP_WRITE)}
  
  protected override def onDispose(): Unit = {
    disposer.dispose()
    super.dispose()
  }
}
